package com.egoo.ticket.server.controller;

import com.egoo.ticket.server.utils.common.ConstantCode;
import com.egoo.ticket.server.utils.common.DbResponse;
import com.egoo.ticket.server.utils.common.ResponseConstant;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Donny_dong
 */
@Slf4j
@RestController
public class BaseController {

	protected String userId;
	protected String tenantId;

	@ModelAttribute
	public void getParam(HttpServletRequest request){
		this.userId = request.getHeader(ConstantCode.CurrentUserInfo.USER_ID);
		this.tenantId = request.getHeader(ConstantCode.CurrentUserInfo.TENANT_ID);

//		Preconditions.checkNotNull(userId,"header中的userId不能为空");
//		Preconditions.checkArgument(!Strings.isNullOrEmpty(tenantId),"header中的tenantId不能为空");
		log.info("header中获取的值：userId:"+userId +"---->tenantId:"+tenantId);

	}

	/**
	 * @Author: Donny_dong
	 * @Description: 判断 header中的userId 和 tenantId 是否存在
	 * @Param:
	 * @return:
	 * @Date: 2020/11/19
	 */
	protected boolean headerParamIsExist() {
		if (StringUtils.isEmpty(userId)){
			return true;
		}
		if (StringUtils.isEmpty(tenantId)){
			return true;
		}
		return false;
	}

}
